
// 初始化 keySettings 列表
final keyFunctionList=[
  KeyOption(value: 0, zh: "无作用", en: "None"),
  KeyOption(value: 3, zh: "上一曲", en: "Previous Track"),
  KeyOption(value: 4, zh: "下一曲", en: "Next Track"),
  KeyOption(value: 5, zh: "播放/暂停", en: "Play/Pause"),
  KeyOption(value: 6, zh: "接听电话", en: "Answer Call"),
  KeyOption(value: 7, zh: "挂断电话", en: "Hang Up"),
  KeyOption(value: 8, zh: "回拨电话", en: "Call Back"),
  KeyOption(value: 9, zh: "音量加", en: "Volume Up"),
  KeyOption(value: 10, zh: "音量减", en: "Volume Down"),
  KeyOption(value: 11, zh: "拍照", en: "Take Photo"),
];
final keySettingsList = KeySettings(
  keyNum: [
    KeyOption(value: 1, zh: "左", en: "Left"),
    KeyOption(value: 2, zh: "右", en: "Right"),
  ],
  keyAction: [
    KeyOption(value: 1, zh: "短按耳机", en: "Single Tap Setting"),
    KeyOption(value: 2, zh: "轻点两下耳机", en: "Double Tap Setting"),
  ],
  keyFunction: [
    KeyOption(value: 0, zh: "无作用", en: "None"),
    KeyOption(value: 3, zh: "上一曲", en: "Previous Track"),
    KeyOption(value: 4, zh: "下一曲", en: "Next Track"),
    KeyOption(value: 5, zh: "播放/暂停", en: "Play/Pause"),
    KeyOption(value: 6, zh: "接听电话", en: "Answer Call"),
    KeyOption(value: 7, zh: "挂断电话", en: "Hang Up"),
    KeyOption(value: 8, zh: "回拨电话", en: "Call Back"),
    KeyOption(value: 9, zh: "音量加", en: "Volume Up"),
    KeyOption(value: 10, zh: "音量减", en: "Volume Down"),
    KeyOption(value: 11, zh: "拍照", en: "Take Photo"),
  ],
);

class KeyOption {
  final int value;
  final String zh;
  final String en;

  KeyOption({required this.value, required this.zh, required this.en});

  factory KeyOption.fromJson(Map<String, dynamic> json) {
    return KeyOption(
      value: json['value'],
      zh: json['title']['zh'],
      en: json['title']['en'],
    );
  }

  Map<String, dynamic> toJson() => {
    'value': value,
    'title': {'zh': zh, 'en': en},
  };
}

class KeySettings {
  final List<KeyOption> keyNum;
  final List<KeyOption> keyAction;
  final List<KeyOption> keyFunction;

  KeySettings({
    required this.keyNum,
    required this.keyAction,
    required this.keyFunction,
  });

  factory KeySettings.fromJson(Map<String, dynamic> json) {
    return KeySettings(
      keyNum: (json['key_num'] as List)
          .map((e) => KeyOption.fromJson(e))
          .toList(),
      keyAction: (json['key_action'] as List)
          .map((e) => KeyOption.fromJson(e))
          .toList(),
      keyFunction: (json['key_function'] as List)
          .map((e) => KeyOption.fromJson(e))
          .toList(),
    );
  }

  Map<String, dynamic> toJson() => {
    'key_num': keyNum.map((e) => e.toJson()).toList(),
    'key_action': keyAction.map((e) => e.toJson()).toList(),
    'key_function': keyFunction.map((e) => e.toJson()).toList(),
  };
}

